using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using ManoMachine.Emulator.CPU;

namespace ManoMachine.IDE.Convertrs
{
    public class CpuContentToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || parameter == null)
            {
                return value;
            }

            var registers = value as Dictionary<Registers, short>;

            if (registers != null)
            {
                Registers currentRegister;
                Enum.TryParse(parameter.ToString(), out currentRegister);

                return registers[currentRegister].ToString("X");
            }
            else
            {
                var flags = value as Dictionary<Flags, bool>;
                Flags currentflag;
                Enum.TryParse(parameter.ToString(), out currentflag);

                return flags[currentflag] ? 1 : 0;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}